﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using NUnit.Framework;
using NUnit.Framework.Constraints;

namespace TimScripts.BF4Rcon.Test
{
    [TestFixture]
    public class MapDataMapCollectionTests
    {
        MapDataCreator MapData;

        [SetUp]
        public void SetUp()
        {
            MapData = new MapDataCreator();
        }

        [Test]
        public void MapsParsedCorrectly()
        {
            IList<string> mapData;
            MapDataMapCollection mapCollection;
            Map[] maps = { 
                             new Map(MapName.DawnBreaker, GameMode.Domination, 5), 
                             new Map(MapName.LancangDam, GameMode.TeamDeathmatch, 44) 
                         };

            mapData = MapData.AddMaps(maps).GetData();

            mapCollection = new MapDataMapCollection(mapData);

            Assert.AreEqual(maps.Length, mapCollection.Count);

            Assert.That(mapCollection, Is.EqualTo(maps).Using(new MapComparer()));
        }

        [Test]
        public void IndexerGetsCorrectMap()
        {
            IList<string> mapData;
            MapDataMapCollection mapCollection;
            Map map = new Map(MapName.DawnBreaker, GameMode.Domination, 5);

            mapData = MapData.AddMaps(map).GetData();

            mapCollection = new MapDataMapCollection(mapData);

            Assert.That(mapCollection[0], Is.EqualTo(map).Using(new MapComparer()));
        }

        [Test]
        public void EmptyMapListParsedCorrectly()
        {
            MapDataMapCollection mapCollection = new MapDataMapCollection(MapData.GetData());

            Assert.AreEqual(0, mapCollection.Count);

            foreach (Map map in mapCollection)
            {
                Assert.Fail("Should be no maps.");
            }
        }

        [Test]
        public void MapsParsedCorrectlyWithOffset()
        {
            IList<string> mapData;
            MapDataMapCollection mapCollection;
            Map[] maps = { 
                             new Map(MapName.DawnBreaker, GameMode.Domination, 5), 
                             new Map(MapName.LancangDam, GameMode.TeamDeathmatch, 44) 
                         };

            mapData = MapData.AddMaps(maps).GetData("OK");

            mapCollection = new MapDataMapCollection(mapData, 1);

            Assert.AreEqual(maps.Length, mapCollection.Count);

            Assert.That(mapCollection, Is.EqualTo(maps).Using(new MapComparer()));
        }
    }
}
